package com.softlab.retailwholesalesystem.controller;


import com.softlab.retailwholesalesystem.entity.DetailOutInWarehouseEntity;
import com.softlab.retailwholesalesystem.entity.VO.OutInWarehouseGoodsVOEntity;
import com.softlab.retailwholesalesystem.service.IDetailOutWarehouseService;
import com.softlab.retailwholesalesystem.service.exception.UpdateErrorException;
import com.softlab.retailwholesalesystem.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/outinwarehouse/detail")
public class DetailOutInWarehouseController {
    @Autowired
    private IDetailOutWarehouseService service;

    @GetMapping("{id}")
    public JsonResult<List<OutInWarehouseGoodsVOEntity>> get(@PathVariable Long id){
        List<OutInWarehouseGoodsVOEntity> list = service.getMap(id);
        return new JsonResult<>(200,"查询调库单详情成功",list);
    }

    @PostMapping
    public JsonResult<Void> add(@RequestBody DetailOutInWarehouseEntity map){
        service.save(map);
        return new JsonResult<>(200,"调库单详情添加成功");
    }

    @DeleteMapping("{id}")
    public JsonResult<Void> delete(@PathVariable Long id){
        DetailOutInWarehouseEntity entity = new DetailOutInWarehouseEntity();
        entity.setIsDelete(1);
        entity.setDetailId(id);
        service.updateById(entity);
        return new JsonResult<>(200,"调库单详情删除成功");
    }

    @PutMapping
    public JsonResult<Void> update(@RequestBody DetailOutInWarehouseEntity map){
        boolean b = service.updateById(map);
        if (b){
            throw new UpdateErrorException("修改时遇到错误");
        }
        return new JsonResult<>(200,"修改成功");
    }

}
